package com.pengweiwei.androidzygote.start;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.DrawableRes;

import com.pengweiwei.androidzygote.databinding.FragmentImageGuideBinding;
import com.putong35.common.baseactfrag.fragment.BaseFragment;


public class ImageGuideFragment extends BaseFragment implements AnimationGuideActivity.PageSelectedListener {

    private @DrawableRes int imageRes;
    private boolean isLastPage;

    private FragmentImageGuideBinding fragmentImageGuideBinding;

    public void clkToApp() {
        getActivity().setResult(Activity.RESULT_OK);
        getActivity().finish();
    }

    public static ImageGuideFragment newInstance(@DrawableRes int imageRes, boolean isLastPage) {
        Bundle args = new Bundle();
        args.putInt("imageRes", imageRes);
        args.putBoolean("isLastPage", isLastPage);
        ImageGuideFragment fragment = new ImageGuideFragment();
        fragment.setArguments(args);
        return fragment;
    }

    public static ImageGuideFragment newInstance(@DrawableRes int imageRes) {
        return newInstance(imageRes, false);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.imageRes = getArguments().getInt("imageRes");
        this.isLastPage = getArguments().getBoolean("isLastPage");
    }


    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        fragmentImageGuideBinding = FragmentImageGuideBinding.inflate(inflater);
        fragmentImageGuideBinding.ivImage.setImageResource(imageRes);
        if (isLastPage) {
            fragmentImageGuideBinding.btnToMain.setVisibility(View.VISIBLE);
        }
        fragmentImageGuideBinding.btnToMain.setOnClickListener( (view -> clkToApp()));
        return fragmentImageGuideBinding.getRoot();
    }

    @Override
    public void onPageSelected() {
        Log.e("pww", "onPageSelected: ");
    }

}
